﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using School.Entities;
using School.Common;
using School.Admission;
using School.Accounting;
using System.Data.Entity;

namespace School.Pages
{
    public partial class MasterALSafa : System.Web.UI.MasterPage
    {
        int[] myarray = new int[7];
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("../Loginpage.aspx");
            }
            //try
            //{

            //    if (Session["UserName"].ToString() != "Admin")
            //    {
            //        int UserId;
            //        UserId = Convert.ToInt32(Session["UserId"]);
            //        if (Session["SesuirtyArray"] == null) 
            //        {
            //        CheckForSecurity(UserId);
            //        }
            //        else
            //        {
            //            myarray = (int[])Session["SesuirtyArray"];
            //            drawMenu();
            //        }
            //    }
            //}
            //catch
            //{
            //}
        }
        protected void CheckForSecurity(int Id)
        {
            
            int counter = 1;

            while (counter < 8)
            {
                Control cr = FindControl("Link" + counter.ToString());
                try
                {

                    if (StuffPagesCls.GetByStuffId(Id, "Link" + counter.ToString()) != -1)
                    {
                        myarray[counter] = 1;
                        cr.Visible = true;
                    }
                    else
                    {
                        myarray[counter] = 0;
                        cr.Visible = false;
                    }
                }
                catch
                {
                    cr.Visible = false;
                    myarray[counter] = 0;
                }
                counter += 1;
            }
            Session["SesuirtyArray"] = myarray;
        }
        protected void drawMenu()
        {

            int counter = 1;

            while (counter < 8)
            {
                Control cr = FindControl("Link" + counter.ToString());
                if (myarray[counter] == 1)
                {
                        
                    cr.Visible = true;
                }
                else
                {
                    cr.Visible = false;
                }
                counter += 1;
            }
            Session["SesuirtyArray"] = myarray;
        }
    }
}
